package com.views {
	import com.Lang;
	import com.utils.LoadResponder;
	import com.views.interfaces.IInitLoading;
	import com.views.structure.Structure;
	import com.lang.views.InitLoadingViewLang;

	public class InitLoadingView extends Base implements IView {
		private var _il:IInitLoading;
		private var _toolbarLoaded:Boolean = false;
		private var _toolbarHandler:Function;

		public function InitLoadingView() {
			super();

		}

		public function show():void {
			this.render();
		}

		public function close():void {
			this.reposition(true);
			this.clear();
			_popup.closeView(this);
			_view.openEvent();
		}

		public function clear():void {

		}

		public function reposition(_arg1:Boolean = true):void {
			var _local2:int;
			var _local3:int;
			if (inStage == false) {
				return;
			}
			if (true == _arg1) {
				_view.toolbar.reposition();
			} else {
				_local2 = Structure.stageWidth;
				_local3 = Structure.stageHeight;
				this._il.content.x = (_local2 - this._il.content.width) / 2;
				this._il.content.y = (_local3 - this._il.content.height) / 2;
			}
			_structure.reposition();
		}

		public function loadChooseRole():void {
			var callback:Function = function():void {
//				_view.chooseRoles.show();
				close();
				backendLoadToolbar();
			}
			this.loadResources(["ChooseRoles"], callback);
		}

		private function loadResources(_arg1:Array, _arg2:Function):void {
			var _local3:LoadResponder = new LoadResponder(_arg2, this.loading);
			_view.loadResources(_arg1, _local3);
		}

		private function render():void {
			if (this._il == null) {
				this._il = _view.getAssetsObject("InitLoading", "InitLoading") as IInitLoading;
				this._il.tip = InitLoadingViewLang.Tip;
			}
			_popup.addView(this, this._il.content);
			this.loading("");
			this._view.closeEvent();
		}

		public function loading(_arg1:String, _arg2:int = 0, _arg3:int = 0, _arg4:int = 1, _arg5:String = ""):void {
			var _local6:String = Lang.sprintf(InitLoadingViewLang.Loading, (_arg3 + 1), _arg4, _arg2, _arg5);
			this.loading1(_local6, _arg2);
		}

		public function loading1(_arg1:String, _arg2:int = 100):void {
			this._il.render(_arg1, _arg2);
			this.reposition(false);
		}

		public function loadToolbar():void {
			if (_view.login.first == false) {
				this.loadToolbar1(this.get_player_info);
			} else {
				if (true == this._toolbarLoaded) {
					this.get_player_info();
				} else {
					if (false == inStage) {
						this.render();
					}
					this._toolbarHandler = this.get_player_info;
				}
			}
		}

		private function loadToolbar1(_loadCallback:Function):void {
//			this.loadResources(["Toolbar", "PanelLoading", "DelayMessage", "Map", "Chat", "Templet"], _loadCallback);
			this.loadResources(["Toolbar", "PanelLoading", "Chat"], _loadCallback);
		}

		public function get_player_info():void {
			_view.formatServerData();
//			_data.call(Mod_Player_Base.get_player_info, this.getPlayerInfoCallback, []);
			getPlayerInfoCallback();
		}

		private function getPlayerInfoCallback():void {
			_view.afterGetPlayerInfo();
		}

		public function backendLoadToolbar():void {
			var callback:Function = function():void {
				if (_toolbarHandler is Function) {
					_toolbarHandler();
				}
				_toolbarLoaded = true;
			}
			this.loadToolbar1(callback);
		}

		public function set tip(str:String):void {
			this._il.tip = str;
		}
	}

}
